﻿using AutoMapper;
using Furion.DynamicApiController;
using System.Threading.Tasks;
using todo.EntityFramework.FromBody;
using todo.EntityFramework.ViewModels.UI;
using todo.books.IServices;
using Microsoft.Extensions.Logging;
using Dapr;
using todo.Core.Configuration;

namespace todo.book.API
{
    public  class BooksController : IDynamicApiController
    {
        private readonly ILogger<BooksController> _logger;
        private readonly IDoBooksServices _dar;
        public BooksController(IDoBooksServices dar, ILogger<BooksController> logger)
        {
            _dar = dar;
            _logger = logger;
        }
        public  Task<AdminUiCallBack> AddBooks(FMBooksInsertModel entity) 
        {
            return _dar.AddBooks(entity);
        }
        public async Task<bool> IsUserExBooksAsync(FMBooksInsertModel entity)
        {
            _logger.LogInformation("[Begin] BooksController Query User data for");
            var IsUser = await _dar.IsUserExBooksAsync(entity);
            _logger.LogInformation("[End] BooksController Query User data for" + IsUser.ToString());
            return IsUser;
        }

        [Topic(RedisMessageQueueKey.pubUserExBooks, "neworder")]
        public async Task<bool> SubProductStock(FMBooksInsertModel entity)
        {
            _logger.LogInformation("[Begin] BooksController SubProductStock User data for");
            var IsUser = await _dar.IsUserExBooksAsync(entity);
            _logger.LogInformation("[End] BooksController SubProductStock User data for");
            return IsUser;
        }
    }
}
